#include <bits/stdc++.h>
using namespace std;
int n,a[2005],nxt[2005],pre[2005];
void solve(){
    cin>>n;
    memset(nxt,0,sizeof(nxt));
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++)
            if(a[i]==a[j]){
                nxt[i]=j;
                break;
            }
    }
    int b[20],ans=0;
    for(int msk=0;msk<(1<<(n+1));msk++){
        int k=msk,cnt=0,sum=0;
        while(k){
            cnt++;
            b[cnt]=k&1;
            k/=2;
        }
        for(int i=1;i<=n;i++){
            if(b[i]==b[nxt[i]]){
                bool f=1;
                for(int j=i+1;j<nxt[i];j++)
                    if(b[j]!=1-a[i])f=0;
                if(f)sum+=a[i];
            }
        }
        ans=max(ans,sum);
    }
    cout<<ans<<endl;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T;
    cin>>T;
    while(T--)solve();
    return 0;
}